<template>
  <div class="p-2">
    <el-row :gutter="20">
      <el-col :lg="24" :xs="24">
        <div v-show="showSearch" class="mb-[10px]">
          <el-card shadow="hover">
            <el-form ref="queryFormRef" :model="queryParams" :inline="true">
              <el-form-item label="用户名称" prop="userName">
                <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable @keyup.enter="handleQuery" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
            </el-form>
          </el-card>
        </div>

        <el-card shadow="hover">
          <template #header>
            <el-row :gutter="10">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
              </el-col>
              <right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading" border :data="listData" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="50" align="center" />
            <template v-for="(item, index) in columns">
              <el-table-column v-if="item.visible" :key="item.key" :label="item.label" align="center" :prop="item.key" >
                <template v-slot="scope">
                  <template v-if="item.key === '任务要求'">
                    <el-tooltip :content="scope.row[item.key]">
                      <div class="zi-hide">{{ scope.row[item.key] }}</div>
                    </el-tooltip>
                  </template>
                </template>
              </el-table-column>
            </template>

            <el-table-column label="操作" fixed="right" width="180" class-name="small-padding fixed-width">
              <template #default="scope">
                <el-button link type="primary" icon="Edit">修改</el-button>
                <el-button link type="primary">发布</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-show="total > 0"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>

    <formVue ref="formRef"></formVue>

  </div>
</template>

<script setup>
// 方法
import { ref } from 'vue'

// 组件
import formVue from '@/views/taskAdmin/scheduled/form.vue'
const formRef = ref(null)

// 列显隐信息
const columns = ref([
  { key: '任务标题', label: `任务标题`, visible: true, children: [] },
  { key: '任务地点', label: `任务地点`, visible: true, children: [] },
  { key: '开始时间', label: `开始时间`, visible: true, children: [] },
  { key: '预计完成时间', label: `预计完成时间`, visible: true, children: [] },
  { key: '任务要求', label: `任务要求`, visible: true, children: [] },
  { key: '备注', label: `备注`, visible: true, children: [] },
  { key: '创建人', label: `创建人`, visible: true, children: [] },
  { key: '执行人', label: `执行人`, visible: true, children: [] },
  { key: '创建时间 ', label: `创建时间`, visible: true, children: [] },
]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
const total = ref(120)
const showSearch = ref(true);
const loading = ref(true);
const listData = ref([
  {
    "任务标题": "生活饮用水常规指标检验",
    "任务地点": "XX市第一自来水厂水源地",
    "开始时间": "2025-07-01 08:30:00",
    "预计完成时间": "2025-07-05 17:00:00",
    "任务要求": "按照GB 5749-2022标准，完成42项常规指标检测，重点关注浊度、余氯、菌落总数等指标，提交完整检测报告",
    "备注": "采样容器需提前灭菌，运输过程需避光冷藏",
    "执行人": "张晓明",
    "创建人": "李建国",
    "创建时间": "2025-06-28 14:20:00"
  },
  {
    "任务标题": "工业废水重金属含量检测",
    "任务地点": "XX化工园区污水处理站",
    "开始时间": "2025-07-03 10:00:00",
    "预计完成时间": "2025-07-07 18:00:00",
    "任务要求": "检测项目包括铅、镉、汞、六价铬等重金属，采用原子吸收光谱法，每2小时采样一次，共采集8个样品",
    "备注": "采样时需穿戴防护装备，样品需加硝酸酸化至pH<2",
    "执行人": "刘芳",
    "创建人": "王志强",
    "创建时间": "2025-06-29 09:15:00"
  },
  {
    "任务标题": "地表水富营养化指标监测",
    "任务地点": "XX湖湖心区及入湖河口",
    "开始时间": "2025-07-05 07:00:00",
    "预计完成时间": "2025-07-10 12:00:00",
    "任务要求": "监测项目为氨氮、总磷、总氮、叶绿素a，每日采样一次，同步测量水温、pH值、溶解氧",
    "备注": "需使用水质多参数检测仪现场测定物理指标，采样后24小时内完成实验室分析",
    "执行人": "赵磊",
    "创建人": "陈红梅",
    "创建时间": "2025-06-30 16:40:00"
  },
  {
    "任务标题": "二次供水微生物指标检验",
    "任务地点": "XX小区高层二次供水水箱",
    "开始时间": "2025-07-07 13:30:00",
    "预计完成时间": "2025-07-09 11:00:00",
    "任务要求": "检测菌落总数、总大肠菌群、耐热大肠菌群，每个水箱采集3个点位样品，平行检测2次",
    "备注": "采样前需对水龙头进行消毒，样品需在4℃条件下保存并于4小时内送检",
    "执行人": "孙鹏",
    "创建人": "周伟",
    "创建时间": "2025-07-01 10:25:00"
  },
  {
    "任务标题": "地下水硬度及硝酸盐氮检测",
    "任务地点": "XX区域地下水监测井群",
    "开始时间": "2025-07-09 09:00:00",
    "预计完成时间": "2025-07-12 16:30:00",
    "任务要求": "对10口监测井进行采样，检测总硬度、硝酸盐氮、亚硝酸盐氮、氨氮指标，采用滴定法和分光光度法",
    "备注": "采样前需抽排井内滞留水，记录井深及水位数据",
    "执行人": "吴敏",
    "创建人": "郑海",
    "创建时间": "2025-07-02 15:10:00"
  }
]);


// 获取数据
const getList = () => {
  loading.value = false
}

// 搜索
const handleQuery = () => {
}

// 重置
const resetQuery = () => {
  for (let i in queryParams.value) {
    if (i !== 'pageNum' && i !== 'pageSize') {
      queryParams.value[i] = undefined
    }
  }
  handleQuery()
}

// 多选
const handleSelectionChange = () => {
}

// 新增
const handleAdd = () => {
  formRef.value.open()
}


getList()
</script>
